package com.example.studyspringdemo.mapper;

import com.example.studyspringdemo.bean.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select({
            "select",
            "id, userName, userNameCn,email,sex,mobile,password",
            "from user"
    })
    List<User> selectAll();

    @Select({
            "select",
            "id, userName, userNameCn,email,sex,mobile,salt,password",
            "from user",
            "where userName = #{userName}"
    })
    List<User> selectUserByUserName(@Param("userName") String userName);

    @Select({
            "select",
            "id, userName, userNameCn,email",
            "from user",
            "where email = #{email}"
    })
    List<User> selectUserByEmail(@Param("email") String email);

    @Insert("insert into user(userName,userNameCn,password,salt,email,sex,mobile) " +
            "values(#{userName},#{userNameCn},#{password},#{salt},#{email},#{sex},#{mobile})")
    @Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
    int saveUser(User user);
}
